package com.mvc.controller;

import com.alibaba.fastjson.JSON;
import com.mvc.entity.Order;
import com.mvc.model.Result;
import com.mvc.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName OrderController
 * @Description TODO
 * @Author Gla
 * @Date 2021/12/2 8:54
 * @Version 1.0
 **/
@Api(tags = "订单详情")
@Controller
@RequestMapping(value = "/order", produces = "text/html;charset=UTF-8")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "订单分页查询",response = Result.class)
    @GetMapping(value = "/search.do")
    @ResponseBody
    public String listSearch(@RequestParam Integer page, @RequestParam Integer limit,
                             @RequestParam(required = false) String shippingNum, @RequestParam(required = false) String receiver_name){
        System.out.println(limit);
        Integer startRow = (page - 1) * limit;

        List<Order> list = orderService.listSearch(startRow,limit,shippingNum,receiver_name);
        Integer count = orderService.getCount(shippingNum,receiver_name);

        Result result = new Result();
        result.setCode(0);
        result.setCount(count);
        result.setData(list);
        String s = JSON.toJSONString(result);
        return s;
    }

}
